﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>DivDialog</title>
    <!-- 引入 layui.css -->
    <link href="layui/css/layui.css" rel="stylesheet">
    <script src="layui/layui.js"></script>
    <script type="text/javascript">

        function OnPageOfficeCtrlInit() {
            // PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
            pageofficectrl.OfficeToolbars = false;
            pageofficectrl.AddCustomToolButton("保存", "Save", 1);
            pageofficectrl.AddCustomToolButton("填写收入证明", "ShowModalDlg()", 1);
            pageofficectrl.AddCustomToolButton("填写个税申请表", "ShowModalDlg2()", 1);
        }
        function Save() {
            //pageofficectrl.WebSave();
            alert('此示例没有编写保存逻辑代码。');
        }
        function ShowModalDlg() {
            pageofficectrl.word.LocateDataRegion("PO_zhengming");
            pageofficectrl.Enabled = false;
            var $ = layui.jquery;
            var index1 = layer.open({
                type: 1, // page 层类型
                area: ['600px', '600px'],
                title: '请填收入证明',
                shade: 0.6, // 遮罩透明度
                shadeClose: false, // 点击遮罩区域，关闭弹层
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: $("#form"),

                success: function (layero, index1) {
                    var btn = layero.find('.layui-btn[lay-filter="ok1"]');
                    btn.on('click', function () {
                        // layer.close(index1);
                    });
                }
            });

            layui.use(function () {
                var form = layui.form;
                // 当表单元素被动态插入时，需主动进行组件渲染才能显示
                form.render(); // 渲染全部表单
                // 提交事件
                form.on('submit(ok1)', function (data) {
                    var field = data.field; // 获取表单字段值
                    pageofficectrl.word.SetValueToDataRegion('PO_name', field.name);
                    pageofficectrl.word.SetValueToDataRegion('PO_sex', field.gender);
                    pageofficectrl.word.SetValueToDataRegion('PO_idCard', field.idCard);
                    pageofficectrl.word.SetValueToDataRegion('PO_startDate', startDate);
                    pageofficectrl.word.SetValueToDataRegion('PO_job', field.position);
                    pageofficectrl.word.SetValueToDataRegion('PO_salary', field.salary);
                    layer.close(index1);
                    return false; // 阻止默认 form 跳转
                });
            });
        }
        function ShowModalDlg2() {
            //定位光标到书签处
            pageofficectrl.word.LocateDataRegion("PO_shenqingbiao");
            pageofficectrl.Enabled = false;
            var $ = layui.jquery;
            var index2 = layer.open({
                type: 1, // page 层类型
                area: ['600px', '600px'],
                title: '请填申请表信息',
                shade: 0.6, // 遮罩透明度
                shadeClose: false, // 点击遮罩区域，关闭弹层
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: $("#form1"),
                success: function (layero, index2) {
                    var btn = layero.find('.layui-btn[lay-filter="ok2"]');
                    btn.on('click', function () {
                        // layer.close(index2);
                    });
                }
            });

            layui.use(function () {
                var form = layui.form;
                // 当表单元素被动态插入时，需主动进行组件渲染才能显示
                form.render(); // 渲染全部表单
                form.on('submit(ok2)', function (data) {
                    var field = data.field; // 获取表单字段值
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonName', field.name);
                    if ('男' == field.gender) {
                        pageofficectrl.word.SetValueToDataRegion('PO_PersonGender', '☑男 □女');
                    } else {
                        pageofficectrl.word.SetValueToDataRegion('PO_PersonGender', '□男 ☑女');
                    }
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonAge', field.age.toString());
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonNation', field.nation);
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonIDType', field.id_type);
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonID', field.unit_no);
                    pageofficectrl.word.SetValueToDataRegion('PO_PersonReason', field.unit_reason);
                    layer.close(index2);
                    return false; // 阻止默认 form 跳转
                });
            });
        }

    </script>
</head>
<body>
    <!--**************   卓正 PageOffice组件 ************************-->
    <div style=" width:auto; height:900px;">
        @Html.Raw(ViewBag.poCtrl)
    </div>
    <form class="layui-form " action="" id="form" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="男" title="男" checked>
                <input type="radio" name="gender" value="女" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证号码</label>
            <div class="layui-input-block">
                <input type="text" name="idCard" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">请选择日期</label>
                <div class="layui-input-inline  layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" class="layui-input" id="startData" placeholder="选择日期">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职务</label>
            <div class="layui-input-block">
                <input type="text" name="position" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工资</label>
            <div class="layui-input-block">
                <input type="text" name="salary" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="ok1">确定</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <form class="layui-form" action="" id="form1" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男" checked>
                <input type="radio" name="gender" value="2" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="number" name="age" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">国籍</label>
            <div class="layui-input-block">
                <select name="nation" lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="中国">中国</option>
                    <option value="美国">美国</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">证件类别</label>
            <div class="layui-input-block">
                <select name="id_type" lay-filter="aihao">
                    <option value="">请选择</option>
                    <option value="身份证">身份证</option>
                    <option value="护照">护照</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">证件号</label>
            <div class="layui-input-block">
                <input type="text" name="unit_no" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">申请理由</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="unit_reason" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="ok2">确定</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        var startDate;
        layui.use(function () {
            var laydate = layui.laydate;
            // 自定义格式
            laydate.render({
                elem: '#startData',
                format: 'yyyy年MM月dd日',
                done: function (value, date, endDate) {
                    //value得到的是日期生成的值，如：2017-08-18
                    //date是一个日期对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0, isLeapYear: false ...}
                    //endDate当类型时range时才会用到，作为结束日期
                    startDate = value;
                }
            });
        });
        function handlePageOfficeCtrlStatus() {
            let layShades = document.getElementsByClassName('layui-layer-shade');

            if (0 == layShades.length) {
                let layNavChildren = document.getElementsByClassName('layui-nav-child');
                for (let i = 0; i < layNavChildren.length; i++) {
                    const attrClass = layNavChildren[i].getAttribute('class');
                    if (attrClass.includes('layui-show')) {
                        pageofficectrl.Enabled = false;
                        return;
                    }
                }
                pageofficectrl.Enabled = true;
            } else {
                pageofficectrl.Enabled = false;
            }

        }
        function bodyBindListener() {
            document.addEventListener('mouseover', function (event) {
                handlePageOfficeCtrlStatus()
            });

            document.addEventListener('mousemove', function (event) {
                handlePageOfficeCtrlStatus()
            });
        }
        bodyBindListener();

    </script>

</body>
</html>
